<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class RoyaltiController extends AdminController {

    public function filters() {
        return array(
            'accessControl', // perform access control for CRUD operations
        );
    }

    public function ActionIndex() {

        if ($_FILES['file_excel']['tmp_name']) {
            Yii::import('application.vendors.PHPExcel', true);
            $objReader = new PHPExcel_Reader_Excel5;
            $objPHPExcel = $objReader->load(@$_FILES['file_excel']['tmp_name']);
            $objWorksheet = $objPHPExcel->getActiveSheet();
            $highestRow = $objWorksheet->getHighestRow(); // e.g. 10
            $highestColumn = $objWorksheet->getHighestColumn(); // e.g 'F'
            $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); // e.g. 5
            //echo '<table>' . "\n";
            for ($row = 2; $row <= $highestRow; ++$row) {
                //echo '<tr>' . "\n";
                for ($col = 0; $col <= $highestColumnIndex; ++$col) {
                    //echo '<td>' . $objWorksheet->getCellByColumnAndRow($col, $row)->getValue() . '</td>' . "\n";

                    $data[$row][] = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
                }
                
                
                
                $rs_insert = Yii::app()->db->createCommand()->insert('installment_payment', array(
                    'installment_payment_network_id' => function_lib::get_network_id($data[$row][0]),
                    'installment_payment_date' => $data[$row][2],
                    'installment_payment_amount' => $data[$row][1],
                        ));
               
                //echo '</tr>' . "\n";
            }
            //echo '</table>' . "\n";
            //print_r($data);
            Yii::app()->user->setFlash('success', 'Data has been saved successfully.');
            
        }

        
        $this->render('create');
    }

    public function ActionList() {
        if ($_POST) {
            die('dadasds');
        }
    }

}

?>
